<?php

/**
 * This is the model class for table "factura".
 *
 * The followings are the available columns in table 'factura':
 * @property integer $idFactura
 * @property string $nombre
 * @property integer $monto_bsf
 * @property integer $Eo_id
 * @property integer $Vendor_idVendor
 *
 * The followings are the available model relations:
 * @property Eo $eo
 * @property Vendor $vendorIdVendor
 */
class Factura extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Factura the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'factura';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('nombre, monto_bsf, Eo_id, Vendor_idVendor', 'required'),
			array('monto_bsf, Eo_id, Vendor_idVendor', 'numerical', 'integerOnly'=>true),
			array('nombre', 'length', 'max'=>45),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('idFactura, nombre, monto_bsf, Eo_id, Vendor_idVendor', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'eo' => array(self::BELONGS_TO, 'Eo', 'Eo_id'),
			'vendorIdVendor' => array(self::BELONGS_TO, 'Vendor', 'Vendor_idVendor'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'idFactura' => 'Id',
			'nombre' => 'Nombre',
			'monto_bsf' => 'Monto Bsf',
			'Eo_id' => 'EO Relacionado',
			'Vendor_idVendor' => 'Vendor',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('idFactura',$this->idFactura);
		$criteria->compare('nombre',$this->nombre,true);
		$criteria->compare('monto_bsf',$this->monto_bsf);
		$criteria->compare('Eo_id',$this->Eo_id);
		$criteria->compare('Vendor_idVendor',$this->Vendor_idVendor);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
        
        
        public function vendor($key=null){
        
            switch ($key){
                case 'all':
                    $list=array();
                    foreach (Vendor::model()->findAll() as $key){
                        $list[$key->idVendor]=$key->nombre;
                    }
                    return $list;
                break;
                default:
                    return Vendor::model()->findByPk($key?$key:$this->idVendor);
                
            }
 
        } 
                
        
        
}